package com.smartleanx.module.hrm.controller.app.memorandum;

import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import com.smartleanx.framework.security.core.annotations.PreAuthenticated;
import com.smartleanx.module.hrm.controller.admin.memorandum.vo.MemorandumListRespVO;
import com.smartleanx.module.hrm.controller.admin.memorandum.vo.MemorandumSaveReqVO;
import com.smartleanx.module.hrm.service.memorandum.MemorandumService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.smartleanx.framework.common.pojo.CommonResult.success;

@Tag(name = "用户APP - 备忘录")
@RestController
@RequestMapping("/hrm/memorandum")
@Validated
public class APPMemorandumController {

    @Resource
    private MemorandumService memorandumService;

    @PostMapping("/create")
    @Operation(summary = "创建备忘录")
    @PreAuthenticated
    public CommonResult<Long> createMemorandum(@Valid @RequestBody MemorandumSaveReqVO createReqVOs) {
        return success(memorandumService.createMemorandum(createReqVOs));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除备忘录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthenticated
    public CommonResult<Boolean> deleteMemorandum(@RequestParam("id") Long id) {
        memorandumService.deleteMemorandum(id);
        return success(true);
    }

    @GetMapping("/getMemorandumList")
    @Operation(summary = "获取当前月和前后两月备忘录列表")
    @Parameter(name = "date", description = "日期", required = true, example = "yyyy-MM-dd")
    @PreAuthenticated
    public CommonResult<List<MemorandumListRespVO>> getMemorandumList(@RequestParam("date") String date) {
        List<MemorandumListRespVO> list = memorandumService.getMemorandumList(date);
        return success(BeanUtils.toBean(list, MemorandumListRespVO.class));
    }

}
